package midalgorithms.list;

import java.util.HashMap;

public class _03CrossedList {
    public static ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null){
            return null;
        }
        HashMap<ListNode,Integer> hashMap = new HashMap<>();
        //遍历链表A
        ListNode pa = headA;
        while (pa != null){
            hashMap.put(pa,1);
            pa = pa.next;
        }
        ListNode pb = headB;
        while (pb != null){
            if (hashMap.containsKey(pb)){
                return pb;
            }
            pb = pb.next;
        }
        return null;
    }
}
